import http from "@/http";

// 根据用户名或姓名分页获取用户列表
export const userListAPI = (params: IUserParams): RES<IWholeMenu<IUserListModel>> =>
  http.get("/admin/list", { params });
//修改账号状态
export const userListStatusAPI = (id: number, status: number): RES<number> =>
  http.post(`/admin/updateStatus/${id}?status=${status}`);
//添加用户
export const addUserAPI = (params: IUserListModel): RES<IUserListModel> =>
  http.post("/admin/register", params);
//获取指定用户
export const userByIdAPI = (id: number): RES<IUserListModel> =>
  http.get(`/admin/${id}`);
//修改指定用户信息
export const editUserAPI = (params: IUserListModel): RES<number> =>
  http.post(`/admin/update/${params.id}`, params);
//获取所有用户角色
export const userRoleAPI = (): RES<IRoleModel[]> => http.get("/role/listAll");
//获取指定的用户角色
export const userRoleByIdAPI = (adminId: number): RES<IRoleModel[]> =>
  http.get(`/admin/role/${adminId}`);
//给用户分配角色
export const userRoleUpdataAPI = (
  adminId: number,
  roleIds: number[]
): RES<number> =>
  http.post(
    `/admin/role/update?adminId=${adminId}&roleIds=${roleIds.join(",")}`
  );
//根据角色名称分页获取角色列表
export const userRoleListAPI = (params: IUserParams): RES<IUserRoleDataModel> =>
  http.get("/role/list", { params });
//添加用户角色
export const addUserRoleAPI = (params: IRoleModel): RES<number> =>
  http.post("/role/create", params);
//编辑用户角色
export const editUserRoleAPI = (id: number, params: IRoleModel): RES<number> =>
  http.post(`/role/update/${id}`, params);
//获取角色相关菜单
export const getRoleListAPI = (roleId: number): RES<IRoleModel> =>
  http.get(`/role/listMenu/${roleId}`);
//获取角色相关资源
export const getListResourceAPI = (roleId: number): RES<IResourceModel[]> =>
  http.get(`/role/listResource/${roleId}`);
//查询所有后台资源
export const getResourceListAllAPI = (): RES<IResourceModel[]> =>
  http.get("/resource/listAll");
//查询所有后台资源分类
export const getResourceCategoryListAllAPI = (): RES<
  IResourceCategoryModel[]
> => http.get("/resourceCategory/listAll");
//给角色分配资源
export const roleAllocResourceAPI = (params: IRoleAllParams): RES<number> =>
  http.post(
    `/role/allocResource?roleId=${
      params.roleId
    }&resourceIds=${params.resourceIds.join(",")}`
  );

// 树形结构返回所有菜单列表
export const treeListApi = (): RES<ITreeList[]> => http.get("/menu/treeList");
//获取角色相关菜单
export const roleListByIdAPI = (roleId: number): RES<IMenuModel[]> =>
  http.get(`/role/listMenu/${roleId}`);
//给角色分配菜单
export const roleAllocMenuAPI = (
  roleId: number,
  menuIds: number[]
): RES<number> =>
  http.post(`/role/allocMenu?roleId=${roleId}&menuIds=${menuIds.join(",")}`);
